BIN = ~/Development/OS/bins/bin
CC = $(BIN)/i386-elf-gcc
CCFLAGS = -ffreestanding

CXX = $(BIN)/i386-elf-gcc
CXXFLAGS = 

AS = $(BIN)/nasm
ASFLAGS = -fbin -o $@ $<

LD = $(BIN)/i386-elf-ld
LDFLAGS = -Tlink.ld -o $@


BINS = Stage1.bin Stage2.bin Stage3.bin Floppy.img
Stage1_SOURCE = ./stage1/entry.o
Stage2_SOURCE = ./stage2/entry.o
Stage3_SOURCE = ./stage3/entry.o

ALL = $(BINS) $(Stage1_SOURCE) $(Stage2_SOURCE) $(Stage3_SOURCE)


all: $(BINS)
	dd if=Stage1.bin of=Floppy.img conv=notrunc
	dd if=Stage2.bin of=Floppy.img conv=notrunc seek=1
	hdiutil mount ./floppy.img
	cp Stage3.bin "/Volumes/xD-BLFLOPPY/Stage3.bin"
	hdiutil unmount "/Volumes/xD-BLFLOPPY/"

Stage1.bin: $(Stage1_SOURCE)
	cp $(Stage1_SOURCE) $@

Stage2.bin: $(Stage2_SOURCE)
	cp $(Stage2_SOURCE) $@

Stage3.bin: $(Stage3_SOURCE)
	cp $(Stage3_SOURCE) $@

Floppy.img:
	dd if=/dev/zero of=./Floppy.img bs=512 count=2880 

.s.o:
	$(AS) $(ASFLAGS)


clean:
	@rm $(ALL)


